<template>
  <div class="category-sidebar">
    <div class="sidebar-header">
      <h3>分类</h3>
      <el-button size="small" @click="$emit('category-manage')">
        管理
      </el-button>
    </div>
    
    <div class="category-list">
      <!-- 全部任务 -->
      <div
        class="category-item"
        :class="{ active: selectedCategoryId === null }"
        @click="$emit('category-select', null)"
      >
        <span class="category-name">📋 全部任务</span>
      </div>

      <!-- 分类列表 -->
      <div
        v-for="category in categories"
        :key="category.categoryId"
        class="category-item"
        :class="{ active: selectedCategoryId === category.categoryId }"
        @click="$emit('category-select', category.categoryId)"
      >
        <span class="category-color" :style="{ backgroundColor: category.color }"></span>
        <span class="category-name">{{ category.name }}</span>
        <span class="task-count">{{ category.taskCount }}</span>
      </div>
    </div>
  </div>
</template>

<script setup>
defineProps({
  categories: {
    type: Array,
    default: () => []
  },
  selectedCategoryId: {
    type: Number,
    default: null
  }
})

defineEmits(['category-select', 'category-manage', 'refresh'])
</script>

<style scoped>
.category-sidebar {
  padding: 20px;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.sidebar-header h3 {
  margin: 0;
  font-size: 16px;
  color: #333;
}

.category-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.category-item {
  display: flex;
  align-items: center;
  padding: 10px 15px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s;
}

.category-item:hover {
  background-color: #f5f7fa;
}

.category-item.active {
  background-color: #ecf5ff;
  color: #409eff;
}

.category-color {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 10px;
}

.category-name {
  flex: 1;
  font-size: 14px;
}

.task-count {
  font-size: 12px;
  color: #909399;
  background-color: #f4f4f5;
  padding: 2px 8px;
  border-radius: 10px;
}
</style>
